import axios from 'axios'
import { getToken } from '@/utils/auth'
const service = axios.create({
  baseURL: '/api',
  timeout: 5000
})
/**
 * @description: 请求拦截器
 * @return {*}
 */
service.interceptors.request.use(
  config => {
    if (getToken()) {
      if (config.headers) config.headers.Token = getToken()
    }
    return config
  },
  error => {
    return Promise.reject(new Error(error))
  }
)
/**
 * @description: 响应拦截器
 * @return {*}
 */
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    console.log(error.response)
    return Promise.reject(new Error(error.response.data))
  }
)
export default service
